﻿using AutoMapper;
using BusinessLogic.Model;
using DataAccess.DAO;
using DataAccess.DAO.Impl;
using DataAccess.Domain;
using DataAccess.EntityHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BusinessLogic.GeneralService
{
    public class ProductService : IProductService
    {
        private IProductRepository productdb;
        public ProductService()
        {
            productdb = new ProductRepository();
        }
        public IList<ProductItem> GetList()
        {
            return Mapper.Map<IList<Product>, IList<ProductItem>>(productdb.GetAll());  
        }
        public void AddNewProduct(ProductAddNew product)
        {
            productdb.Add(Mapper.Map<ProductAddNew, Product>(product));
        }
        public byte[] GetImageFromId(int Id)
        {
            return productdb.GetSingle(m => m.Id == Id).Image;
        }
        public ProductDetail GetProductById(int Id)
        {
            return Mapper.Map<Product, ProductDetail>(productdb.GetSingle(m => m.Id == Id));
        }
    }
}
